home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer Cast
- Date: Tue, 13 Feb 1996 14:01:26 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <31208BA6.167EB0E7@intellektik.informatik.th-darmstadt.de>
- References: <1996Feb12.113703.5882@wisipc.weizmann.ac.il> <4foulo$d8v@adam.telalink.net>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
-
- daver wrote:
- >
- > In article <1996Feb12.113703.5882@wisipc.weizmann.ac.il>, cerlpvk says...
- > >
- > >First question.
- > >
- > >I read somewhere that before the notion of static member functions was
- > >introduced the way around was smth like that.
- > >
- > >(X*)0->func();
- > >Would someone kindly explain what this means.
- > >
- > ...
- >
- > I have never seen the former used before but it is trying to call X::func
- > pretending that NULL points to a valid object. This would generate a crash if
- > X::func attempts to dereference "this" (which static members are prevented from
- > doing), but it does allow X::func to be called without an instance of X. I
- > would not recommend doing this!
- >
-
- I would say it was a sort of programming convention, to express that the appropriate
- function never access members. Such tricks are no longer necessary since 'static'
- member functions exists. In addition one should note that today in general the behavior
- of calling a (non-static) member-function via a 'null' pointer is undefined no matter
- if the function accesses members or not.
-
- Enno
-